package com.seahorse.youliao.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.seahorse.youliao.service.SysDeptService;
import com.seahorse.youliao.service.entity.SysDeptDTO;
import com.seahorse.youliao.utils.BeanUtil;
import com.seahorse.youliao.vo.request.SysDeptQueryVO;
import com.seahorse.youliao.vo.response.SysDeptPageInfoVO;
import com.seahorse.youliao.vo.response.SysDeptResponseVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
* describe: 部门表
* @author : songqiang
* @date: 2020-01-17 09:23:44.242
**/
@RestController
@Api("SysDeptController")
@RequestMapping("sysDept")
@Validated
public class SysDeptController {
	
    private static final Logger LOGGER = LoggerFactory.getLogger(SysDeptController.class);
    
	@Autowired
    private SysDeptService sysDeptService;
    /**
     * 分页查询
     * @param sysDeptQueryVO 分页查询参数
     * @return 分页参数
     */
    @ApiOperation(value = "分页查询")
    @PostMapping("getPageList")
    public SysDeptPageInfoVO selectPageList(@RequestBody @Valid SysDeptQueryVO sysDeptQueryVO) {
        String info = String.format("The method name[selectPageList] params:%s", sysDeptQueryVO.toString());
        LOGGER.info(info);
        SysDeptDTO sysDept = BeanUtil.convert(sysDeptQueryVO, SysDeptDTO.class);

        Page<SysDeptResponseVO> page = PageHelper.startPage(sysDeptQueryVO.getPageNum(), sysDeptQueryVO.getPageSize());
        List<SysDeptDTO> sysDeptList = sysDeptService.getList(sysDept);
        SysDeptPageInfoVO sysDeptPageInfo = new SysDeptPageInfoVO();
        BeanUtils.copyProperties(page.toPageInfo(), sysDeptPageInfo);
        List<SysDeptResponseVO> voList = BeanUtil.convert(sysDeptList, SysDeptResponseVO.class);
        sysDeptPageInfo.setList(voList);

        return sysDeptPageInfo;
    }


}
